<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   在Apache Spark上跑Logistic Regression算法  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/20101.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466454838: Accept with keywords: (title(0.5):Spark,社区,算法,数盟, topn(0.533333333333):社区,数盟,文件夹,应用程序,数据挖掘,数值,出错率,Python,标签,模型,内存,计算结果,计算,文章,Spark,数据,教程,预测,对象,Hadoop,算法,实例,spark,驱动程序,编程语言,分类,测试数据,集群,变量,分布式).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    在Apache Spark上跑Logistic Regression算法
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    在Apache Spark上跑Logistic Regression算法 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,83] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/20101.html">
          在Apache Spark上跑Logistic Regression算法
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          2,665 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech" rel="category tag">
          文章
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        作者：Leonard Giura 出处：
        <a href="http://www.csdn.net/article/2015-07-24/2825285">
         csdn
        </a>
       </p>
       <p>
        本文旨在介绍使用机器学习算法，来介绍Apache Spark数据处理引擎。我们一开始会先简单介绍一下Spark，然后我们将开始实践一个机器学习的例子。我们将使用Qualitative Bankruptcy数据集，来自UCI机器学习数据仓库。虽然Spark支持同时Java，Scala，Python和R，在本教程中我们将使用Scala作为编程语言。不用担心你没有使用Scala的经验。练习中的每个代码段，我们都会详细解释一遍。
       </p>
       <p>
        <b>
         APACHE SPARK
        </b>
       </p>
       <p>
        Apache Spark是一个开源的集群计算框架，用Spark编写的应用程序可以比Hadoop MapReduce范式的速度高100倍以上。Spark的一个主要的特点，基于内存，运行速度快，不仅如此，复杂应用在Spark系统上运行，也比基于磁盘的MapReduce更有效。Spark还旨在更通用，因此它提供了以下库：
       </p>
       <ul>
        <li>
         Spark SQL，处理结构化数据的模块
        </li>
        <li>
         MLlib，可扩展的机器学习库
        </li>
        <li>
         GraphX，图和图的并行计算API
        </li>
        <li>
         Spark Streaming，可扩展的，可容错的流式计算程序
        </li>
       </ul>
       <p>
        正如已经提到的，Spark支持Java，Scala，Python和R编程语言。它还集成了其他大数据工具。特别是，Spark可以运行在Hadoop集群，可以访问任何数据源，包括Hadoop Cassandra。
       </p>
       <p>
        <b>
         Spark核心概念
        </b>
       </p>
       <p>
        在一个高的抽象层面，一个Spark的应用程序由一个驱动程序作为入口，在一个集群上运行各种并行操作。驱动程序包含了你的应用程序的main函数，然后将这些应用程序分配给集群成员执行。驱动程序通过SparkContext对象来访问计算集群。对于交互式的shell应用，SparkContext默认可通过sc变量访问。
       </p>
       <p>
        Spark的一个非常重要的概念是RDD–弹性分布式数据集。这是一个不可改变的对象集合。每个RDD会分成多个分区，每个分区可能在不同的群集节点上参与计算。RDD可以包含任何类型的Java，Scala对象，Python或R，包括用户自定义的类。RDDS的产生有两种基本方式：通过加载外部数据集或分配对象的集合如，list或set。
       </p>
       <p>
        在创建了RDDs之后，我们可以对RDDs做2种不同类型的操作：
       </p>
       <ul>
        <li>
         Transformations – 转换操作，从一个RDD转换成另外一个RDD
        </li>
        <li>
         Actions – 动作操作，通过RDD计算结果
        </li>
       </ul>
       <p>
        RDDs通过lazy的方式计算 – 即当RDDs碰到Action操作时，才会开始计算。Spark的Transformations操作，都会积累成一条链，只有当需要数据的时候，才会执行这些Transformations操作。每一次RDD进行Action操作时，RDD都会重新生成。如果你希望某些中间的计算结果能被其他的Action操作复用，那么你需要调用Spark的RDD.persist()来保存中间数据。
       </p>
       <p>
        Spark支持多种运行模式，你可以使用交互式的Shell，或者单独运行一个standalone的Spark程序。不管哪一种方式，你都会有如下的工作流：
       </p>
       <ul>
        <li>
         输入数据，用于生成RDD
        </li>
        <li>
         使用Transformations 操作转换数据集
        </li>
        <li>
         让Spark保存一些中间计算结果，用于复用计算
        </li>
        <li>
         使用Action操作，让Spark并行计算。Spark内部会自动优化和运行计算任务。
        </li>
       </ul>
       <p>
        <b>
         安装Apache Spark
        </b>
       </p>
       <p>
        为了开始使用Spark，需要先从
        <a href="http://spark.apache.org/downloads.html" target="_blank">
         官网
        </a>
        下载。选择“Pre-built for Hadoop 2.4 and later”版本然后点击“Direct Download”。如果是Windows用户，建议将
        <a href="http://spark.apache.org/" target="_blank">
         Spark
        </a>
        放进名字没有空格的文件夹中。比如说，将文件解压到：C:\spark。
       </p>
       <p>
        正如上面所说的，我们将会使用Scala编程语言。进入Spark的安装路径，运行如下命令：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c53c9588174334" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          // Linux and Mac users

bin/spark-shell

// Windows users

bin\spark shell
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c53c9588174334-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53c9588174334-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53c9588174334-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53c9588174334-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53c9588174334-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53c9588174334-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53c9588174334-7">
               7
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c53c9588174334-1">
               <span class="crayon-c">
                // Linux and Mac users
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53c9588174334-2">
              </div>
              <div class="crayon-line" id="crayon-57685325c53c9588174334-3">
               <span class="crayon-v">
                bin
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-v">
                spark
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-v">
                shell
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53c9588174334-4">
              </div>
              <div class="crayon-line" id="crayon-57685325c53c9588174334-5">
               <span class="crayon-c">
                // Windows users
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53c9588174334-6">
              </div>
              <div class="crayon-line" id="crayon-57685325c53c9588174334-7">
               <span class="crayon-v">
                bin
               </span>
               <span class="crayon-sy">
                \
               </span>
               <span class="crayon-e">
                spark
               </span>
               <span class="crayon-v">
                shell
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0008 seconds] -->
       <p>
        然后你可以在控制台中看到Scala：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c53d8377087463" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          scala&amp;gt;
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c53d8377087463-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c53d8377087463-1">
               <span class="crayon-v">
                scala
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0006 seconds] -->
       <p>
        <b>
         QUALITATIVE 破产分类
        </b>
       </p>
       <p>
        现实生活中的问题是可以用机器学习算法来预测的。我们将试图解决的，通过一个公司的定性信息，预测该公司是否会破产。数据集可以从UCI机器学习库https://archive.ics.uci.edu/ml/datasets/qualitative_bankruptcy下载。在Spark的安装文件夹中，创建一个新的文件夹命名为playground。复制 qualitative_bankruptcy.data.txt文件到这里面。这将是我们的训练数据。
       </p>
       <p>
        数据集包含250个实例，其中143个实例为非破产，107个破产实例。
       </p>
       <p>
        每一个实例数据格式如下：
       </p>
       <ul>
        <li>
         工业风险
        </li>
        <li>
         管理风险
        </li>
        <li>
         财务灵活性
        </li>
        <li>
         信誉
        </li>
        <li>
         竞争力
        </li>
        <li>
         经营风险
        </li>
       </ul>
       <p>
        这些被称为定性参数，因为它们不能被表示为一个数字。每一个参数可以取下以下值：
       </p>
       <ul>
        <li>
         P positive
        </li>
        <li>
         A average
        </li>
        <li>
         N negative
        </li>
       </ul>
       <p>
        数据集的最后一个列是每个实例的分类：B为破产或NB非破产。
       </p>
       <p>
        鉴于此数据集，我们必须训练一个模型，它可以用来分类新的数据实例，这是一个典型的分类问题。
       </p>
       <p>
        解决问题的步骤如下：
       </p>
       <ul>
        <li>
         从qualitative_bankruptcy.data.txt文件中读取数据
        </li>
        <li>
         解析每一个qualitative值，并将其转换为double型数值。这是我们的分类算法所需要的
        </li>
        <li>
         将数据集划分为训练和测试数据集
        </li>
        <li>
         使用训练数据训练模型
        </li>
        <li>
         计算测试数据的训练误差
        </li>
       </ul>
       <p>
        <b>
         SPARK LOGISTIC REGRESSION
        </b>
       </p>
       <p>
        我们将用Spark的逻辑回归算法训练分类模型。如果你想知道更多逻辑回归算法的原理，你可以阅读以下教程http://technobium.com/logistic-regression-using-apache-mahout。
       </p>
       <p>
        在Spark的Scala Shell中粘贴以下import语句：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c53e1320751232" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          import org.apache.spark.mllib.classification.{LogisticRegressionWithLBFGS, LogisticRegressionModel}

import org.apache.spark.mllib.regression.LabeledPoint

import org.apache.spark.mllib.linalg.{Vector, Vectors}
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c53e1320751232-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e1320751232-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e1320751232-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e1320751232-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e1320751232-5">
               5
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c53e1320751232-1">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-v">
                org
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                apache
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                spark
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                mllib
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                classification
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-v">
                LogisticRegressionWithLBFGS
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                LogisticRegressionModel
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e1320751232-2">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e1320751232-3">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-v">
                org
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                apache
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                spark
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                mllib
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                regression
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                LabeledPoint
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e1320751232-4">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e1320751232-5">
               <span class="crayon-e">
                import
               </span>
               <span class="crayon-v">
                org
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                apache
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                spark
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                mllib
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                linalg
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-v">
                Vector
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Vectors
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0020 seconds] -->
       <p>
        这将导入所需的库。
       </p>
       <p>
        接下来我们将创建一个Scala函数，将数据集中的qualitative数据转换为Double型数值。键入或粘贴以下代码并回车，在Spark Scala Shell。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c53e7059752686" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          def getDoubleValue( input:String ) : Double = {

    var result:Double = 0.0

    if (input == "P")  result = 3.0 

    if (input == "A")  result = 2.0

    if (input == "N")  result = 1.0

    if (input == "NB") result = 1.0

    if (input == "B")  result = 0.0

    return result

   }
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53e7059752686-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53e7059752686-17">
               17
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c53e7059752686-1">
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                getDoubleValue
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-t">
                String
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                Double
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-2">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                var
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                result
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-t">
                Double
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.0
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-4">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "P"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                result
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-6">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "A"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                result
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2.0
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-8">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "N"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                result
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1.0
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-10">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "NB"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                result
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1.0
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-12">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "B"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                result
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.0
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-14">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-15">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                result
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53e7059752686-16">
              </div>
              <div class="crayon-line" id="crayon-57685325c53e7059752686-17">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0041 seconds] -->
       <p>
        如果所有的运行都没有问题，你应该看到这样的输出：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c53ee499009964" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          getDoubleValue: (input: String)Double
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c53ee499009964-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c53ee499009964-1">
               <span class="crayon-v">
                getDoubleValue
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                input
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                String
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-t">
                Double
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0008 seconds] -->
       <p>
        现在，我们可以读取到qualitative_bankruptcy.data.txt文件中的数据。从Spark的角度来看，这是一个Transformation操作。在这个阶段，数据实际上不被读入内存。如前所述，这是一个lazy的方式执行。实际的读取操作是由count()引发，这是一个Action操作。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c53f4170200049" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          val data = sc.textFile("playground/Qualitative_Bankruptcy.data.txt")

data.count()
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c53f4170200049-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c53f4170200049-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685325c53f4170200049-3">
               3
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c53f4170200049-1">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                sc
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                textFile
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "playground/Qualitative_Bankruptcy.data.txt"
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c53f4170200049-2">
              </div>
              <div class="crayon-line" id="crayon-57685325c53f4170200049-3">
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                count
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0011 seconds] -->
       <p>
        用我们val关键字声明一个常量data。它是一个包含输入数据所有行的RDD。读操作被SC或sparkcontext上下文变量监听。count操作应返回以下结果：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c53fa830004465" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          res0: Long = 250
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c53fa830004465-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c53fa830004465-1">
               <span class="crayon-v">
                res0
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                Long
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                250
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0008 seconds] -->
       <p>
        现在是时候为逻辑回归算法准备数据，将字符串转换为数值型。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c5400875105948" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          val parsedData = data.map{line =

    val parts = line.split(",")

    LabeledPoint(getDoubleValue(parts(6)), Vectors.dense(parts.slice(0,6).map(x =getDoubleValue(x))))

}
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c5400875105948-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c5400875105948-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685325c5400875105948-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c5400875105948-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685325c5400875105948-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c5400875105948-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685325c5400875105948-7">
               7
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c5400875105948-1">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                parsedData
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                data
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                map
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-v">
                line
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c5400875105948-2">
              </div>
              <div class="crayon-line" id="crayon-57685325c5400875105948-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                parts
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                line
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                split
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                ","
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c5400875105948-4">
              </div>
              <div class="crayon-line" id="crayon-57685325c5400875105948-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                LabeledPoint
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                getDoubleValue
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                parts
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                Vectors
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                dense
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                parts
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                slice
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                6
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                map
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-e">
                getDoubleValue
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c5400875105948-6">
              </div>
              <div class="crayon-line" id="crayon-57685325c5400875105948-7">
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0086 seconds] -->
       <p>
        在这里，我们声明了另外一个常量，命名为parsedData。对于data变量中的每一行数据，我们将做以下操作：
       </p>
       <ul>
        <li>
         使用“，”拆分字符串，并获得一个向量，命名为parts
        </li>
        <li>
         创建并返回一个LabeledPoint对象。每个LabeledPoint包含标签和值的向量。在我们的训练数据，标签或类别（破产或非破产）放在最后一列，数组下标0到6。这是我们使用的parts(6)。在保存标签之前，我们将用getDoubleValue()函数将字符串转换为Double型。其余的值也被转换为Double型数值，并保存在一个名为稠密矢量的数据结构。这也是Spark的逻辑回归算法所需要的数据结构。
        </li>
       </ul>
       <p>
        Spark支持map()转换操作，Action动作执行时，第一个执行的就是map()。
       </p>
       <p>
        我们来看看我们准备好的数据，使用take():
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c5406462961427" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          parsedData.take(10)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c5406462961427-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c5406462961427-1">
               <span class="crayon-v">
                parsedData
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                take
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0007 seconds] -->
       <p>
        上面的代码，告诉Spark从parsedData数组中取出10个样本，并打印到控制台。一样的，take()操作之前，会先执行map()。输出结果如下：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c540c440321809" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          res5: Array[org.apache.spark.mllib.regression.LabeledPoint] = Array((1.0,[3.0,3.0,2.0,2.0,2.0,3.0]), (1.0,[1.0,1.0,2.0,2.0,2.0,1.0]), (1.0,[2.0,2.0,2.0,2.0,2.0,2.0]), (1.0,[3.0,3.0,3.0,3.0,3.0,3.0]), (1.0,[1.0,1.0,3.0,3.0,3.0,1.0]), (1.0,[2.0,2.0,3.0,3.0,3.0,2.0]), (1.0,[3.0,3.0,2.0,3.0,3.0,3.0]), (1.0,[3.0,3.0,3.0,2.0,2.0,3.0]), (1.0,[3.0,3.0,2.0,3.0,2.0,3.0]), (1.0,[3.0,3.0,2.0,2.0,3.0,3.0]))
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c540c440321809-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c540c440321809-1">
               <span class="crayon-v">
                res5
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                Array
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                org
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                apache
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                spark
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                mllib
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                regression
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                LabeledPoint
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                Array
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                2.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-cn">
                3.0
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0131 seconds] -->
       <p>
        接着我们划分一下训练数据和测试数据，将parsedData的60%分为训练数据，40%分为测试数据。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c5413967949966" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          val splits = parsedData.randomSplit(Array(0.6, 0.4), seed = 11L)

val trainingData = splits(0)

val testData = splits(1)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c5413967949966-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c5413967949966-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685325c5413967949966-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c5413967949966-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685325c5413967949966-5">
               5
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c5413967949966-1">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                splits
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                parsedData
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                randomSplit
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-t">
                Array
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0.6
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.4
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                seed
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                11L
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c5413967949966-2">
              </div>
              <div class="crayon-line" id="crayon-57685325c5413967949966-3">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                trainingData
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                splits
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c5413967949966-4">
              </div>
              <div class="crayon-line" id="crayon-57685325c5413967949966-5">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                testData
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                splits
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0079 seconds] -->
       <p>
        训练数据和测试数据也可以像上面一样，使用take()者count()查看。
       </p>
       <p>
        激动人心的时刻，我们现在开始使用Spark的LogisticRegressioinWithLBFGS()来训练模型。设置好分类个数，这里是2个（破产和非破产）：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c5419178332960" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          val model = new LogisticRegressionWithLBFGS().setNumClasses(2).run(trainingData)
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c5419178332960-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c5419178332960-1">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                new
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                LogisticRegressionWithLBFGS
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                setNumClasses
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                run
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                trainingData
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0011 seconds] -->
       <p>
        当模型训练完，我们可以使用testData来检验一下模型的出错率。
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c541f327491199" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          val labelAndPreds = testData.map { point =

  val prediction = model.predict(point.features)

  (point.label, prediction)

}

val trainErr = labelAndPreds.filter(r = r._1 != r._2).count.toDouble / testData.count
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c541f327491199-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c541f327491199-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57685325c541f327491199-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c541f327491199-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57685325c541f327491199-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c541f327491199-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57685325c541f327491199-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57685325c541f327491199-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57685325c541f327491199-9">
               9
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c541f327491199-1">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                labelAndPreds
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                testData
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-i">
                map
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                point
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c541f327491199-2">
              </div>
              <div class="crayon-line" id="crayon-57685325c541f327491199-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                prediction
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                model
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                predict
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                point
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                features
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c541f327491199-4">
              </div>
              <div class="crayon-line" id="crayon-57685325c541f327491199-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                point
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                label
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                prediction
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c541f327491199-6">
              </div>
              <div class="crayon-line" id="crayon-57685325c541f327491199-7">
               <span class="crayon-sy">
                }
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57685325c541f327491199-8">
              </div>
              <div class="crayon-line" id="crayon-57685325c541f327491199-9">
               <span class="crayon-e">
                val
               </span>
               <span class="crayon-v">
                trainErr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                labelAndPreds
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-e">
                filter
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                r
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                r
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                _1
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                !=
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                r
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                _2
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                count
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                toDouble
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                /
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                testData
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-v">
                count
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0089 seconds] -->
       <p>
        变量labelAndPreds保存了map()转换操作，map()将每一个行转换成二元组。二元组包含了testData的标签数据(point.label，分类数据)和预测出来的分类数据(prediction)。模型使用point.features作为输入数据。
       </p>
       <p>
        最后一行代码，我们使用filter()转换操作和count()动作操作来计算模型出错率。filter()中，保留预测分类和所属分类不一致的元组。在Scala中_1和_2可以用来访问元组的第一个元素和第二个元素。最后用预测出错的数量除以testData训练集的数量，我们可以得到模型出错率：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57685325c5425724195551" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          trainErr: Double = 0.20430107526881722
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57685325c5425724195551-1">
               1
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57685325c5425724195551-1">
               <span class="crayon-v">
                trainErr
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                Double
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0.20430107526881722
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0008 seconds] -->
       <p>
        <b>
         总结
        </b>
       </p>
       <p>
        在这个教程中，你已经看到了Apache Spark可以用于机器学习的任务，如logistic regression。虽然这只是非分布式的单机环境的Scala shell demo，但是Spark的真正强大在于分布式下的内存并行处理能力。
       </p>
       <p>
        在大数据领域，Spark是目前最活跃的开源项目，在过去几年已迅速获得关注和发展。在过去的几年里。采访了超过2100受访者，各种各样的使用情况和环境。
       </p>
       <p>
        <b>
         [参考资料]
        </b>
       </p>
       <p>
        “Learning Spark” by HoldenKarau, Andy Konwinski, Patrick Wendell and Matei Zaharia, O’Reilly Media 2015
       </p>
       <p>
        Lichman, M. (2013). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science
       </p>
       <p>
        <a href="https://spark.apache.org/docs/latest/mllib-linear-methods.html#logistic-regression">
         https://spark.apache.org/docs/latest/mllib-linear-methods.html#logistic-regression
        </a>
       </p>
       <p>
        <a href="https://spark.apache.org/docs/1.1.0/mllib-data-types.html">
         https://spark.apache.org/docs/1.1.0/mllib-data-types.html
        </a>
       </p>
       <p>
        <a href="https://archive.ics.uci.edu/ml/datasets/Qualitative_Bankruptcy">
         https://archive.ics.uci.edu/ml/datasets/Qualitative_Bankruptcy
        </a>
       </p>
       <p>
        <a href="https://databricks.com/blog/2015/01/27/big-data-projects-are-hungry-for-simpler-and-more-powerful-tools-survey-validates-apache-spark-is-gaining-developer-traction.html">
         https://databricks.com/blog/2015/01/27/big-data-projects-are-hungry-for-simpler-and-more-powerful-tools-survey-validates-apache-spark-is-gaining-developer-traction.html
        </a>
       </p>
       <p>
        <b>
         原文来自：
        </b>
        <a href="http://technobium.com/logistic-regression-using-apache-spark/">
         LOGISTIC REGRESSION USING APACHE SPARK
        </a>
        （译者/施聪羽 审校/朱正贵 责编/仲浩）
       </p>
       <p>
        <b>
         关于译者：
        </b>
        <a href="http://blog.csdn.net/wsscy2004">
         施聪羽
        </a>
        ，浩渺科技服务端研发工程师，关注大数据处理。
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/20824.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t018630756a7e263b33-300x165.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20824.html" rel="bookmark" title="如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘">
         如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20820.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/1-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20820.html" rel="bookmark" title="人们对Python在企业级开发中的10大误解">
         人们对Python在企业级开发中的10大误解
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20811.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t0133fcacae8523307b_副本-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20811.html" rel="bookmark" title="大神亲传：26条深度学习的金科玉律！">
         大神亲传：26条深度学习的金科玉律！
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20808.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/640.webp-11-300x137.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20808.html" rel="bookmark" title="我们是如何在一张地图上表现86万个数据的">
         我们是如何在一张地图上表现86万个数据的
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F20101.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/20101.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/20101.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>